package com.xuan.controller;
import com.xuan.common.util.R;
import com.xuan.entity.Student;
import com.xuan.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/student")
public class StudentController {
    //显示学生列表
    @Autowired
    private StudentService studentService;
    @GetMapping("/findlist")
    public R findAll(){
        List<Student> list = studentService.list();
        return R.ok().data("students",list);
    }

    //查找班级
    @GetMapping("/findAllClass")
    public List<Student> findAllClass(){
        return  studentService.findAllClass();
    }
    @PostMapping("/Add")
    public R Add(@RequestBody Student student){
        if(studentService.Add(student) > 0) return R.success("添加学生成功");
        else return R.error("添加学生失败！");
    }
}

